
/**
 * File: Student.java
 * Project: CMSC 345 - VirtualAdvisor
 * @author Wallace Brown
 * Date: April 26, 2011
 * E-mail: brownw1@umbc.edu 
 * Description: The class maintaining the student's name, 
 * 		majors and minors.
 */

package virtualadvisor;

import java.util.Iterator;
import java.util.List;

public class Student {

	private static String Default = "default";
	private String name;
	private List<String> major;
	private String minor;

	/**
	 * Name: Student
	 * Precondition: None
	 * Postcondition: Returns a Student object.
	 */
	public Student() {
		name = Student.Default;
		minor = Student.Default;
	}

	/**
	 * Name: Student
	 * Precondition: None
	 * Postcondition: returns a Student object.
	 */
	public Student(String name, List<String> major, String minor) {
		this.name = name;
		this.major = major;
		this.minor = minor;
	}
	
	/**
	 * Name: GetName
	 * Precondition: None
	 * Postcondition: returns the student's name.
	 */
	public String getName() { return new String(name); }

	/**
	 * Name: GetMajor
	 * Precondition: None
	 * Postcondition: returns the student's list of majors.
	 */
	public List<String> getMajor() { return major; }
	
	/**
	 * Name: GetMinor
	 * Precondition: None
	 * Postcondition: returns the student's list of minors.
	 */
	public String getMinor() { return minor; }
	
	/**
	 * Name: GetMajor
	 * Precondition: None
	 * Postcondition: returns the student's list of majors.
	 */
	public void setMajor(List<String> major) { this.major = major; }
	
	/**
	 * Name: GetMinor
	 * Precondition: None
	 * Postcondition: returns the student's list of minors.
	 */
	public void setMinor(String minor) { this.minor = minor; }
	
	/**
	 * Name: getFileMajor
	 * precondition: None
	 * Postcondition: Gets a string of the major(s)
	 * @return
	 */
	public String getFileMajor(){
		if(major.size() == 0)
			return "";
		else {
			Iterator<String> iterator = major.iterator();
			String temp = "";
			while(iterator.hasNext())
				temp = temp + iterator.next() + "_";
			return temp;
		}
	}
	
	/**
	 * Name: XMLCoder
	 * Precondition: None
	 * Postcondition: Gathers information on class to be displayed 
	 *              in XML format for saving to file.
	 * @return - Output on the class to be displayed in XML format
	 */
    public String XMLCoder() {
 	   String xml = "";
 	   
 	   for(String temp: major)
 		  xml = xml + " <major>" + temp + "</major>\n";
 	   
 	   if(!minor.equals(""))
 		   xml = xml + " <minor>" + minor + "</minor>\n";
 	   
 	   return xml;
    }
    
	public String toString() {
		String text = "";
		
		if(name == "")
			text = "Student Name: None\n";
		else
			text = "Student Name: " + name + "\n";
		
		
		if(major == null)
			text = text + "Major: None\n";
		else {
			text = text + "Major: ";
			for(int x = 0; x < major.size(); x++){
				text = text + major.get(x) + ", ";
			}
			text = text + "\n";
		}
		
		if(minor == "")
			text = text + "Minor: None\n";
		else
			text = text + "Minor: " + minor + "\n";
		
		return text;
	}
}
